package configuration;


import org.junit.*;
import java.util.HashSet;
public class ConfigTests {
	static Configuration ty;

	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
		ConfigTests.ty = new Configuration("test.xml");
		ConfigTests.ty.addEntry("Willp", "gow", "junit", "works");
		ConfigTests.ty.addEntry("Will2", "gow", "junit4", "rocks");
		ConfigTests.ty.addEntry("Will2", "gow", "junit3", "not as good");
	}

	@Test
	public void testAddRemove() {
		try {
			ConfigTests.ty.addEntry("Test", "Testing", "Tester", "TestCase");
			Assert.assertTrue(ConfigTests.ty.isEntry("Test", "Testing",
					"Tester"));
			ConfigTests.ty.removeEntry("Test", "Testing");
			Assert.assertFalse(ConfigTests.ty.isEntry("Test", "Testing",
					"Tester"));
		} catch (final EntryExists e) {
		} catch (final NoEntryException e) {
		}
	}

	@Test
	public void testAddRemoveA() {
		try {
			ConfigTests.ty
					.addEntry("TestA", "TestingA", "TesterA", "TestCaseA");
			Assert.assertTrue(ConfigTests.ty.isEntry("TestA", "TestingA",
					"TesterA"));
			ConfigTests.ty.removeEntry("TestA", "TestingA", "TesterA");
			Assert.assertTrue(ConfigTests.ty.isEntry("TestA", "TestingA"));
			Assert.assertFalse(ConfigTests.ty.isEntry("TestA", "TestingA",
					"TesterA"));
		} catch (final EntryExists e) {
		} catch (final NoEntryException e) {
		}
	}

	@Test
	public void testForExistanceFalse() {
		Assert.assertFalse(ConfigTests.ty.isEntry("Willp", "g"));
	}

	@Test
	public void testForExistanceFalseMod() {
		Assert.assertFalse(ConfigTests.ty.isEntry("willpt", "gow"));
	}

	@Test
	public void testForExistanceTrue() {
		Assert.assertTrue(ConfigTests.ty.isEntry("Willp", "gow"));
	}

	@Test
	public void testForValueA() {
		try {
			Assert.assertTrue(ConfigTests.ty.getEntry("Willp", "go", "tell")
					.equals(new String("it")));
		} catch (final NoEntryException e) {
		}
	}
	@Test
	public void testForChange() {
		try {
			ConfigTests.ty
			.addEntry("TestA", "TestingA", "TesterA", "TestCaseA");
			Assert.assertTrue(ConfigTests.ty.getEntry("TestA", "TestingA", "TesterA")
					.equals(new String("TestCaseA")));
			ConfigTests.ty.changeEntry("TestA", "TestingA", "TesterA", "TestCaseB");
			Assert.assertTrue(ConfigTests.ty.getEntry("TestA", "TestingA", "TesterA")
					.equals(new String("TestCaseB")));
		}
		catch (final Exception e) {
			
		}
	}
@Test
public void testTags() {
	try {
	HashSet <String> testSet;
	testSet = new HashSet<String>();
	testSet.add("junit3");
	testSet.add("junit4");
	Assert.assertTrue(ConfigTests.ty.getTags("Will2", "gow").equals(testSet));
	testSet.add("junit5");
	Assert.assertFalse(ConfigTests.ty.getTags("Will2", "gow").equals(testSet));
	
	}
	catch (final Exception e) {
		
	}
}

	@AfterClass
	public static void writer() throws Exception {
		ConfigTests.ty.removeEntry("Willp", "gow");
		ConfigTests.ty.removeEntry("TestA", "TestingA");
		ConfigTests.ty.removeEntry("Will2", "gow");
		ConfigTests.ty.writeFile();
	}
}